<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 表单弹窗 -->
      <!-- <form lay-filter="systemEmailInfoForm" class="layui-form model-form" id="systemEmailInfoForm">
                <input id="id" name="id" type="hidden"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否SSL加密</label>
                    <div class="layui-input-block">
                        <input type="radio" name="isSsl" value="0" title="否"/>
                        <input type="radio" name="isSsl" value="1" title="是" checked/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件服务器主机地址</label>
                    <div class="layui-input-block">
                        <input name="smtpServer" placeholder="请输入邮件服务器主机地址" type="text" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">服务器端口</label>
                    <div class="layui-input-block">
                        <input name="port" placeholder="请输入服务器端口" type="text" class="layui-input" lay-verify="required"
                               required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件发送帐号</label>
                    <div class="layui-input-block">
                        <input name="sendAccount" placeholder="请输入邮件发送帐号" type="text" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱登录密码</label>
                    <div class="layui-input-block">
                        <input name="emailPassword" placeholder="请输入邮箱登录密码" type="text" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱回复地址</label>
                    <div class="layui-input-block">
                        <input name="replySite" placeholder="请输入邮箱回复地址" type="text" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发送测试邮件</label>
                    <div class="layui-input-block">
                        <input name="testSendSite" placeholder="请输入发送测试邮件" type="text" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">编码</label>
                    <div class="layui-input-block">
                        <select name="coding">
                            <option></option>
                            <option value="0">UTF-8</option>
                            <option value="1">GBK</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item text-right">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                    <button class="layui-btn" lay-filter="systemEmailInfoFormSubmit" lay-submit>保存</button>
                </div>
            </form> -->
      <form id="cjtSystemEmailInfoForm" class="layui-form" lay-filter="cjtSystemEmailInfoForm">
        <input name="id" type="hidden" />

        <div class="layui-form-item">
          <label class="layui-form-label">appKey</label>
          <div class="layui-input-block">
            <input type="text" name="appKey" class="layui-input" lay-verify="required" required />
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">密钥</label>
          <div class="layui-input-block">
            <input type="text" name="appSecret" class="layui-input" lay-verify="required" required />
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">消息密钥</label>
          <div class="layui-input-block">
            <input type="text" name="appMsgSecret" class="layui-input" lay-verify="required" required />
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">授权密码</label>
          <div class="layui-input-block">
            <input type="text" name="authSecret" class="layui-input" lay-verify="required" required />
          </div>
        </div>

        <div class="layui-form-item text-right">
          <button class="layui-btn" lay-filter="cjtsystemEmailInfoFormSubmit" lay-submit>保存</button>
        </div>
      </form>
    </div>
  </div>
</div>
<style>
  #systemEmailInfoForm .layui-form-label {
    width: 125px;
    padding-left: 0;
  }
  #systemEmailInfoForm .layui-input-block {
    margin-left: 150px;
  }
</style>
<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var admin = layui.admin;
    const { data } = await admin.reqPro("chanjet/chanjetSet/admin/chanjetSet/get", {});
    form.val("cjtSystemEmailInfoForm", data);
    console.log("res", data);
    // list();
    //初始化表单
    // function list() {
    //   admin.req(
    //     "enterprise/system/admin/systemEmailInfo/list",
    //     {},
    //     function (res) {
    //       form.val("systemEmailInfoForm", res.data[0]);
    //       form.render();
    //     },
    //     "GET"
    //   );
    // }
    // 表单提交事件
    form.on("submit(systemEmailInfoFormSubmit)", function (d) {
      if ($("#id").val() != "") {
        admin.req(
          "enterprise/system/admin/systemEmailInfo/update",
          d.field,
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
            list();
          },
          "PUT"
        );
      } else {
        admin.req(
          "enterprise/system/admin/systemEmailInfo/add",
          d.field,
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
            } else {
              layer.msg(res.msg, { icon: 2 });
            }
            list();
          },
          "POST"
        );
      }

      return false;
    });
    form.on("submit(cjtsystemEmailInfoFormSubmit)", function (d) {
      admin.req('chanjet/chanjetSet/admin/chanjetSet/update',d.field,function(res){
        if(res.code == 200){
          layer.msg(res.msg,{icon:1})
        }else{
          layer.msg(res.msg,{icon:2})
        }
      },'PUT')
      return false; 
    });
  });
</script>
